using System;
using System.Collections.Generic;
using System.Text;

namespace WorkTracker.BusinessObjects
{
	/// <summary>
	/// Encapsulates user of the application.
	/// </summary>
	public class User
	{

		#region Properties

		/// <summary>
		/// Database ID of the user
		/// </summary>
		public int ID {
			get { return _id; }
			set { _id = value; }
		}
		private int _id;

		/// <summary>
		/// Name of the user.
		/// </summary>
		public string Name {
			get { return _name; }
			set { _name = value; }
		}
		private string _name;

		/// <summary>
		/// Work hours per day of the user.
		/// </summary>
		public float WorkHoursPerDay {
			get { return _workHoursPerDay; }
			set { _workHoursPerDay = value; }
		}
		private float _workHoursPerDay = 8;

		/// <summary>
		/// Work hours per day without break.
		/// </summary>
		public float WorkHoursPerDayNoBreak {
			get { return _workHoursPerDay - _maximumBreakPerDay; }
		}

		/// <summary>
		/// Maximum break hours of the user (not used).
		/// </summary>
		public float MaximumBreakPerDay {
			get { return _maximumBreakPerDay; }
			set { _maximumBreakPerDay = value; }
		}
		private float _maximumBreakPerDay=0.5f;

		/// <summary>
		/// Current user.
		/// </summary>
		public static User CurrentUser {
			get { 
                if(_currentUser == null)
                    _currentUser =  DataAccessLayer.GetUser(Environment.UserName);
                return _currentUser; 
            }
			set {
				if (value == null)
					throw new ArgumentNullException("value");
				if (_currentUser != value) {
					_currentUser = value;
					if (CurrentUserChanged != null)
						CurrentUserChanged(null, EventArgs.Empty);
				}
			}
		}
        private static User _currentUser;

		/// <summary>
		/// Event which is raised when the current user is changed.
		/// </summary>
		public static event EventHandler CurrentUserChanged;

		#endregion

	}
}
